/**
*  \file adc.h
*
*  \brief ADC sample function
*
*  \author dajin.li  <dajin.li@linde-china.cn>
*
*/

/*===============================================[ public includes  ]================================================*/
#ifndef _ADC_HW_H_
#define _ADC_HW_H_

#include <xmc4500/processor.h>

/*================================================[ public defines   ]================================================*/

/* P14.0  VADC.G0CH0*/
/* unused current */
#define adc_raw_P14_0()                          (((VADC_G0->RES[15] & 0xffff) + (VADC_G0->RES[14] & 0xffff) ) >> 1)

/* P14.1 TEMP_MOT_A_IN_A_CPU_V VADC.G0CH1*/
#define adc_raw_P14_1()                          ((VADC_G0->RES[14] & 0xffff))
#define adc_raw_temp_mot_inv1_in()               ((VADC_G0->RES[14] & 0xffff))

/* P14.2 +5V_EXTERNAL_SENSORS_A_CPU_V  VADC.G0CH2,  VADC.G1CH0*/
#define adc_raw_P14_2()                          ((VADC_G0->RES[9] & 0xffff))
#define adc_raw_5v_ext_sensor()                  ((VADC_G0->RES[9] & 0xffff))

/* P14.3 12v_driver_supply    VADC.G0CH3,   VADC.G1CH3,*/
#define adc_raw_P14_3()                          (((VADC_G0->RES[0] & 0xffff) + (VADC_G0->RES[1] & 0xffff) ) >> 1)
#define adc_raw_12v_driver_supply()              (((VADC_G0->RES[0] & 0xffff) + (VADC_G0->RES[1] & 0xffff) ) >> 1)

/* P14.4  VADC.G0CH4, VADC.G2CH0*/
/* unused current */
#define adc_raw_P14_4()                          (((VADC_G0->RES[2] & 0xffff) + (VADC_G0->RES[3] & 0xffff) ) >> 1)

/* P14.5 DC_LINK_+_IN_A_CPU_V VADC.G0CH5, VADC.G2CH1 */
#define adc_raw_P14_5()                          ((VADC_G0->RES[10] & 0xffff))
#define adc_raw_dc_link_in()                     ((VADC_G0->RES[10] & 0xffff))


/* P14.6 ACCELERATOR_1_IN_A_CPU_V VADC.G0CH6,*/
#define adc_raw_P14_6()                          (((VADC_G0->RES[12] & 0xffff) + (VADC_G0->RES[13] & 0xffff) ) >> 1)
#define adc_raw_accelerator_1_in()               (((VADC_G0->RES[12] & 0xffff) + (VADC_G0->RES[13] & 0xffff) ) >> 1)

/* P14.7 +13.7V_SUPPLY_A_CPU_V VADC.G0CH7,*/
#define adc_raw_P14_7()                          ((VADC_G0->RES[7] & 0xffff))
#define adc_raw_13_7_v_supply()                  ((VADC_G0->RES[7] & 0xffff))

/* P14.8 STEER_ANGLE_B_IN_A_CPU_V VADC.G1CH0,VADC.G3CH2,*/
#define adc_raw_P14_8()                          (((VADC_G1->RES[0] & 0xffff) + (VADC_G1->RES[1] & 0xffff) + (VADC_G1->RES[2] & 0xffff) + (VADC_G1->RES[3] & 0xffff) + (VADC_G3->RES[0] & 0xffff) + (VADC_G3->RES[1] & 0xffff) + (VADC_G3->RES[2] & 0xffff) + (VADC_G3->RES[3] & 0xffff)) >> 3)
#define adc_raw_steer_angle_b_in()               (((VADC_G1->RES[0] & 0xffff) + (VADC_G1->RES[1] & 0xffff) + (VADC_G1->RES[2] & 0xffff) + (VADC_G1->RES[3] & 0xffff) + (VADC_G3->RES[0] & 0xffff) + (VADC_G3->RES[1] & 0xffff) + (VADC_G3->RES[2] & 0xffff) + (VADC_G3->RES[3] & 0xffff)) >> 3)

/* P14.9 RESERVE_2_IN_A_CPU_V VADC.G1CH1,VADC.G3CH3,*/
#define adc_raw_P14_9()                          (((VADC_G1->RES[11] & 0xffff) + (VADC_G3->RES[4] & 0xffff)) >> 1)
#define adc_raw_reserve_2_in()                   (((VADC_G1->RES[11] & 0xffff) + (VADC_G3->RES[4] & 0xffff)) >> 1)

/* P14.12 TEMP_MOT_B_IN_A_CPU_V VADC.G1CH4,*/
#define adc_raw_P14_12()                         ((VADC_G1->RES[7] & 0xffff))
#define adc_raw_temp_mot_inv2_in()               ((VADC_G1->RES[7] & 0xffff))

/* P14.13 CURRENT_CUT-OFF_ISO_VALVE_A_CPU_V VADC.G1CH5,*/
#define adc_raw_P14_13()                         ((VADC_G1->RES[10] & 0xffff))
#define adc_raw_current_cut_off_iso_value()      ((VADC_G1->RES[10] & 0xffff))

/* P14.14 ACCELERATOR_2_IN_A_CPU_V VADC.G1CH6,*/
#define adc_raw_P14_14()                         (((VADC_G1->RES[12] & 0xffff) + (VADC_G1->RES[13] & 0xffff) + (VADC_G1->RES[14] & 0xffff) + (VADC_G1->RES[15] & 0xffff)) >> 2)
#define adc_raw_accelerator_2_in()               (((VADC_G1->RES[12] & 0xffff) + (VADC_G1->RES[13] & 0xffff) + (VADC_G1->RES[14] & 0xffff) + (VADC_G1->RES[15] & 0xffff)) >> 2)

/* P14.15 CURRENT_MAIN_CONTACTOR_A_CPU_V VADC.G1CH7,*/
#define adc_raw_P14_15()                         ((VADC_G1->RES[9] & 0xffff))
#define adc_raw_current_main_contactor()         ((VADC_G1->RES[9] & 0xffff))

/* P15.2 RESERVE_1_IN_A_CPU_V VADC.G2CH2,*/
#define adc_raw_P15_2()                          (((VADC_G2->RES[12] & 0xffff) + (VADC_G2->RES[13] & 0xffff) + (VADC_G2->RES[14] & 0xffff) + (VADC_G2->RES[15] & 0xffff)) >> 2)
#define adc_raw_reserve_1_in()                   (((VADC_G2->RES[12] & 0xffff) + (VADC_G2->RES[13] & 0xffff) + (VADC_G2->RES[14] & 0xffff) + (VADC_G2->RES[15] & 0xffff)) >> 2)


/* P15.3 STEER_ANGLE_A_IN_A_CPU_V VADC.G2CH3,*/
#define adc_raw_P15_3()                          (((VADC_G2->RES[0] & 0xffff) + (VADC_G2->RES[1] & 0xffff) + (VADC_G2->RES[2] & 0xffff) + (VADC_G2->RES[3] & 0xffff)) >> 2)
#define adc_raw_steer_angle_a_in()               (((VADC_G2->RES[0] & 0xffff) + (VADC_G2->RES[1] & 0xffff) + (VADC_G2->RES[2] & 0xffff) + (VADC_G2->RES[3] & 0xffff)) >> 2)

/* P15.8 VADC.G3CH0,*/
/*current unused*/
#define adc_raw_P15_8()                          (((VADC_G3->RES[12] & 0xffff) + (VADC_G3->RES[13] & 0xffff) + (VADC_G3->RES[14] & 0xffff) + (VADC_G3->RES[15] & 0xffff)) >> 2)


/* P15.9 KEY_SWITCH_IN_A_CPU_V VADC.G3CH1,*/
#define adc_raw_P15_9()                          ((VADC_G3->RES[9] & 0xffff))
#define adc_raw_key_switch_in()                  ((VADC_G3->RES[9] & 0xffff))

/*================================================[ public datatypes ]================================================*/

/*================================================[ public variables ]================================================*/

/*================================================[ inline functions ]================================================*/

/*================================================[ public functions ]================================================*/
extern void adc_hardware_init(void);


#endif


